package File;

import java.io.File;

public class ReadFile {

    public static void main(String[] args) {
//        File file = new File("D:\\ApplicationSoft\\[WPF]JJDown\\Download\\NodeJs\\Node.JS-黑马程序员");
//        File[] flies = file.listFiles();
//        reFileName(flies,"day");

        File file =  new File("D:\\ApplicationSoft\\[WPF]JJDown\\Download");
        File[] files = file.listFiles();
        for (File f :
                files) {
            if (f.isDirectory()){
                File[] files1 = f.listFiles();
                for (File f2 :
                        files1) {
                    System.out.println(f2.getName());
                }


            }
        }
        getFile(file);
    }

    public static void getFile(File file){
        if (!file.exists()){
            System.out.println("我不存在");
            return;
        }

        if (file.isFile()){
            System.out.println(file.getName());
        }else{
            File [] files = file.listFiles();
            for (File f :
                    files) {
                if (f.isFile()){
                    System.out.println(f.getName());
                }else{
                    getFile(f);
                }
            }
            return;
        }
    }



    public static void reFileName(File[] flies,String flag){

        for (File file :
                flies) {
            System.out.println(file.getName());
            String name = file.getName();
            if (name.contains(flag)) {
                String s = file.getParent() +"\\"+ name.substring(name.indexOf("")+1,name.length()) ;
                System.out.println("s:" + s);
                File fd = new File(s);
                file.renameTo(fd);
            }
        }
    }



    public static void getFileName(String dirName,String flag,String matches){
        File file = new File("D:\\ApplicationSoft\\[WPF]JJDown\\Download\\NodeJs\\Node.JS-黑马程序员");
        System.out.println(file.getParent());

        File[] flies = file.listFiles();

        for (File fileTemp :
                flies) {
            System.out.println(fileTemp.getName());
            String name = fileTemp.getName();
            if (name.contains("day")) {
                String s = fileTemp.getParent() +"\\"+ name.substring(name.indexOf("")+1,name.length()) ;
                System.out.println("s:" + s);
                File fd = new File(s);
                fileTemp.renameTo(fd);
            }
        }
    }

}
